/*
 *  ExceptionConstants.h
 *  MarketDataColloctor
 *
 *  Created by jiro on 10/03/09.
 *  Copyright 2010 jiro music. All rights reserved.
 *
 */

#import <Cocoa/Cocoa.h>

const NSString* const kText_JdbcClassPath = @"/usr/local/pgsql/share/java/jdbc4.jar";

const NSString* const kText_NotImplementedException			= @"NotImplementedException";
const NSString* const kText_SelectorIsNotImplemented		= @"selector is not implemented.";
const NSString* const kText_NeedInheritClassImplementation	= @"need inherit class implementation.";
const NSString* const kText_DbOperationNotSuccess			= @"Db Operation Not Success";
const NSString* const kText_ApplicationErrorException		= @"Application Error";

const double hoursForOneDay = 24;
const double minuetsForOneHour = 60;
const double secondsForOneMinuet = 60;
const double secondsForOneHour = secondsForOneMinuet * minuetsForOneHour;
const double secondsForOneDay = hoursForOneDay * secondsForOneHour;

const int kNSCalendarUnitAll = 
	NSEraCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit |
	NSMinuteCalendarUnit | NSSecondCalendarUnit | NSWeekCalendarUnit | NSWeekdayCalendarUnit | NSWeekdayOrdinalCalendarUnit;
	
class WeekDay
{
public:
	enum Type
	{
		Type_Sunday = 1,
		Type_Monday,
		Type_Tuesday,
		Type_Wednesday,
		Type_Thursday,
		Type_Friday,
		Type_Saturday,
	};
	
	static NSString* toString( Type type )
	{
		switch ( type )
		{
		case Type_Monday:
			return @"Monday";
		case Type_Tuesday:
			return @"Tuesday";	
		case Type_Wednesday:
			return @"Wednesday";
		case Type_Thursday:
			return @"Thursday";
		case Type_Friday:
			return @"Friday";
		case Type_Saturday:
			return @"Saturday";
		case Type_Sunday:
			return @"Sunday";
		default:
			return nil;
		}
	}
};

class TimeUnit
{
public:
	enum Type
	{
		Type_Year,
		Type_Month,
		Type_Week,
		Type_Day,
		Type_Hour,
		Type_Minuet,
		Type_Second,
		Type_Count
	};
	
	static Type toType( NSString* s )
	{
		for ( int i = 0; i < Type_Count; i++ )
		{
			Type type = static_cast< TimeUnit::Type >( i );
			if ( [ s isEqualToString: toString( type ) ] )
			{
				return type;
			}
		}
		return Type_Count;
	}

	static NSString* toString( Type type )
	{
		switch ( type )
		{
		case Type_Year:
			return @"Year";
		case Type_Month:
			return @"Month";
		case Type_Week:
			return @"Week";
		case Type_Day:
			return @"Day";
		case Type_Hour:
			return @"Hour";
		case Type_Minuet:
			return @"Minuet";
		case Type_Second:
			return @"Second";
		default:
			return nil;
		}
	}
	
	static double seconds( Type type )
	{
		switch ( type )
		{
		case Type_Year:
			return 365 * secondsForOneDay;
		case Type_Month:
			return 30 * secondsForOneDay;
		case Type_Week:
			return 7 * secondsForOneDay;
		case Type_Day:
			return secondsForOneDay;
		case Type_Hour:
			return secondsForOneHour;
		case Type_Minuet:
			return secondsForOneMinuet;
		case Type_Second:
			return 1;
		default:
			return 0;
		}
	}
};

class InvestmentPosition
{
public:
	enum Type
	{
		Type_Short,
		Type_Long,
	};

	static NSString* toString( Type type )
	{
		if ( type == Type_Short )
		{
			return @"Short";
		}
		return @"Long";
	}
	
	static Type toType( NSString* s )
	{
		if ( [ s isEqualToString: toString( Type_Short ) ] )
		{
			return Type_Short;
		}
		return Type_Long;
	}
};

